import React from "react";
import {Icon, NavBar} from "antd-mobile";
import Fund_price from "../../components/Fund_idetail/fund_price";
import Fund_history from "../../components/Fund_idetail/fund_history";
import Fund_record from "../../components/Fund_idetail/fund_record";
import Fund_purchase from "../../components/Fund_idetail/fund_purchase";
import "../../Style/fund.css";
import axios from "axios";
import "../../config.js"
axios.defaults.timeout = 50000;

let fundId = window.location.href;
fundId = fundId.toString().split('=');
if (fundId.length == 2){
    fundId = fundId[1] + '';
}
let zeronum = 0
for(var i=0;i<fundId.length;i++){
    if(fundId[i] == 0){
        zeronum = zeronum+1;
    }else {
        break;
    }
}
console.log(zeronum)
fundId = fundId.slice(zeronum,)
console.log(fundId)

// function getattr() {
//     let childs =document.getElementById("fundID");
//     console.log(childs.innerText)
//     return childs.innerText;
// }

export default class Fund_info extends React.Component{
    constructor(props) {
        super(props);
        this.state={
            fund_data:[],
        };
        var FUNDID=window.location.href.split('=')[1];
        axios.get(global.routes.database+'/getFunds', {
            params: {
                fundID: FUNDID,
            }
        }).then((res)=>{
            console.log(res.data.Data)


            switch (res.data.Data.FCODE.toString().length) {
                case 1:
                    res.data.Data.FCODE = '00000'+res.data.Data.FCODE.toString();
                    break;
                    case 2:
                        res.data.Data.FCODE = '0000'+res.data.Data.FCODE.toString();
                        break;
                    case 3:
                        res.data.Data.FCODE = '000'+res.data.Data.FCODE.toString();
                        break;
                    case 4:
                      res.data.Data.FCODE = '00'+res.data.Data.FCODE.toString();
                        break;
                    case 5:
                        res.data.Data.FCODE = '0'+res.data.Data.FCODE.toString();
                        break;
                    case 6:
                        res.data.Data.FCODE = res.data.Data.FCODE.toString();
                        break;
                }
            document.getElementById("SHORTNAME").innerHTML=res.data.Data.SHORTNAME;
            document.getElementById("FCODE").innerHTML=res.data.Data.FCODE;
        })
        ;
    };
    render() {
        return (
            <div>
                <NavBar className="f_r_nav"
                        mode="light"
                        leftContent={[
                            <Icon type="left" />,
                            "返回",
                        ]}
                        onLeftClick={
                            () =>
                                window.location.href = '#/terran/fundrank'
                        }
                        rightContent={[
                            <Icon key="0" type="search"  />,
                        ]}
                >
                    <div style={{width:'200px',margin:'0 auto',padding:'0',textAlign:'center'}}>
                        <p style={{fontSize:'12px',margin:'0',padding:'0',overflow:'hidden',whiteSpace:'nowrap',textOverflow:'ellipsis'}} id="SHORTNAME">基金名称（加载中...）</p>
                        <p id="fundID" style={{fontSize:'8px',margin:'0',padding:'0'}} id="FCODE">基金代码</p>
                    </div>
                </NavBar>
                <Fund_price/>
                <div style={{width:'100%',height:'10px',background:'rgb(245,245,247)'}}></div>
                <Fund_history/>
                <Fund_record/>
                <div style={{width:'100%',height:'20px',background:'rgb(245,245,247)'}}></div>
                <div style={{width:'100%',display:'flex',top:'0',height:'100%'}}>
                    <div style={{width:'50%',color:'white',background:'rgb(35,122,201)',margin:'0',padding:'0',lineHeight:'50px',textAlign:'center',position:'relative'}}
                         onClick={() => {
                            var phoneNum=document.cookie.split(';')[0].split('=')[1];
                            if(phoneNum==="null"||document.cookie===''){
                                alert('您还没有登陆，无法购买基金！');
                            }else{
                                alert('功能完善中，请直接点击买入（反正不要钱）');
                                //window.location.href = '#/terran/fundsimulationbuy?FundID='+window.location.href.split('=')[1];
                            }
                         }}>模拟买入</div>
                    <div style={{width:'50%',color:'white',background:'rgb(35,122,201)',margin:'0',padding:'0',lineHeight:'50px',textAlign:'center',position:'relative'}}
                         onClick={() => {
                            var phoneNum=document.cookie.split(';')[0].split('=')[1];
                            if(phoneNum==="null"||document.cookie===''){
                                alert('您还没有登陆，无法购买基金！');
                            }else{
                                window.location.href = '#/terran/fundbuy?FundID='+window.location.href.split('=')[1];
                            }
                         }}>买入</div>
                </div>
                <div style={{width:'100%',height:'50px'}}></div>
            </div>
        );
    };
};